import { getBaseUrl } from '@/services/urlconst';
import { requestFunComponFiex } from '@/utils';
import { useMemo } from 'react';
import { useRequest } from 'umi';

const baseUrl = getBaseUrl();

/**
 * 查看当前流程进度
 * @controller 业务controller
 * @returns
 */
const getImageByProcInstIDService = (controller: string) => {
  const getImageByProcInstID = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/${controller}/getImageByProcInstID/${params?.procInstID}`;
      return requestFunComponFiex('GET', personUrl, {});
    },
    {
      manual: true,
      onSuccess: () => {},
    },
  );

  const data = useMemo(() => {
    return getImageByProcInstID?.data;
  }, [getImageByProcInstID?.data]);

  return {
    getImageByProcInstIDRun: getImageByProcInstID?.run,
    getImageByProcInstIDLoading: getImageByProcInstID?.loading,
    getImageByProcInstIDData: data,
  };
};

/**
 * 会签加签
 * @addMulitiCallback 业务controller
 * @returns
 */
const addMulitiService = (
  addMulitiCallback: (res: any) => void,
  controller: string,
) => {
  const addMuliti = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/${controller}/addMuliti`;
      return requestFunComponFiex('POST', personUrl, params);
    },
    {
      manual: true,
      onSuccess: addMulitiCallback,
    },
  );

  return {
    addMulitiRun: addMuliti?.run,
    addMulitiLoading: addMuliti?.loading,
  };
};

export { getImageByProcInstIDService, addMulitiService };
